-
Notifications
You must be signed in to change notification settings - Fork 492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support PagerDuty API v2 #1795
Support PagerDuty API v2 #1795
Conversation
eb99c6f
to
beea7ae
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! Just a few questions below.
services/pagerduty2/service.go
Outdated
Class string | ||
Component string | ||
Group string | ||
CustomDetails string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the above it looks like this field can be arbitrary JSON, is that correct? If so the type could be map[string]interface{}
or possibly just interface{}
something and we could add the details
JSON as this field.
See the VictorOps handler for how the details can be treated as rich data instead of just a string https://github.com/influxdata/kapacitor/blob/master/services/victorops/service.go#L208. The models.Result
type support JSON marshalling so it possibly could be set as the CustomDetails directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was following the existing pagerduty
description which actually has this as a standard string. A local commit type set CustomDetails
to the map[string]interface{}
you called out because that does seem to be the most flexible.
https://github.com/influxdata/kapacitor/blob/master/services/pagerduty/service.go#L155
Do we want to change this one too?
services/pagerduty2/service.go
Outdated
severity = "critical" | ||
case alert.Info: | ||
severity = "info" | ||
case alert.Error: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the alert.Error level get set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, this is my reading of the API v2 docs and not the internal representation from the kapacitor
side...I'll remove.
Thanks for the feedback! Still working to get the tests to pass fully before checking once more (comments in-line). |
@nathanielc mind taking another look? I've incorporated your feedback (hopefully)... |
5d19e43
to
04d4ac5
Compare
Not sure where this test is failing, but still looking into the fix for this one...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebito91 This is really close. I think we can simplify how the CustomDetails are handled, see my comments below.
Let me know what you think....
ap.DedupKey = incidentKey | ||
ap.EventAction = eventType | ||
|
||
ap.Payload.CustomDetails = make(map[string]interface{}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be simpler and still just as useful if the CustomDetails where just the data.Result object. The Result object serializes to JSON in a standard format and contains all relevant data to the alert. Will it still work for your use case to just ignore the details
string and pass in the Result directly? This way we can avoid any edge cases with trying to unmarshal the details strings since its opaque to the code at this point. Thoughts?
To be clear I am thinking something like this
ap.Payload.CustomDetails = make(map[string]interface{})
ap.Payload.CustomDetails["result"] = data.Result
Since the details strings can only be constructed using the data already in data.Result, then this is a superset of the data being provided. The only question is if the data is still useful if we do it this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that makes sense. WIll update and get back to you ASAP!
services/pagerduty2/service.go
Outdated
event.State.ID, | ||
event.State.Message, | ||
event.State.Level, | ||
event.State.Details, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the above comment we can probably just remove passing the details down if they are not going to be used.
9810aad
to
f1f4e1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went through similar process for OpsGenie(#1823) and in the process I noticed a few small things that would be nice to add to this PR:
- Add a
pagerduty2
configuration section to the example config inetc/kapacitor/kapacitor.conf
- Add integration tests for pagerDuty2 in
integrations/streamer_test.go
, copy pasting the existing pagerDuty tests is fine. They will need to be updated for the new API structures - pipeline/tick/alert.go needs to support the new pagerDuty2 handlers
- Add a test to
pipeline/tick/alert_test.go
Thanks for your work on the PR so far!! If you find that you do not have time to finish up some of these items let me know. This is all top of mind for me now and I don't mind finishing up these small housekeeping items since the majority of the work is done.
server/server_test.go
Outdated
}} | ||
|
||
fmt.Printf("DEBUG -- got: %v\n", got[0].PostData.Payload) | ||
fmt.Printf("DEBUG -- exp: %v\n", exp[0].PostData.Payload) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make these either t.Log
or remove them?
0df83a8
to
874ed58
Compare
@nathanielc apologies for the noise on this PR but I believe I've finally covered the updates you were looking for. Thanks again for your patience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sebito91 One last round and this is good to go!
Can you make the two small changes noted below?
Then once they are complete can you rebase and squash the commits into a single commit?
Once that is done I'll merge this. Thanks!
alert/types.go
Outdated
@@ -125,6 +125,7 @@ const ( | |||
Warning | |||
Critical | |||
maxLevel | |||
Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unused correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll remove this one for now, but it is technically an option for the v2 API.
https://v2.developer.pagerduty.com/docs/send-an-event-events-api-v2
Since I'm not explicitly using it in the service then it's fine to ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, eventually Kapacitor may support custom alert levels, right now it tries to keep things simple by implementing what is common between most alert services.
Once there is room for customization here, we can enable the pagerduty2 to take advantage of it.
Thanks.
services/pagerduty2/service.go
Outdated
m := timestamp.Format(time.RFC3339Nano) | ||
if timestamp.Nanosecond() == 0 { | ||
m = time.Unix(timestamp.Unix(), 1).In(timestamp.Location()).Format(time.RFC3339Nano) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just trying to ensure that the timestamps are correctly padded with zeros? And it does so by adding a single nanosecond? If so there is another way to do this. Go's time formatting docs don't make it super clear but in the format string if you use the digit 0
as a placeholder then it will correctly pad the string to be a fixed width.
From the Go source:
RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
If you use this format instead, then zero padding will be added.
"2006-01-02T15:04:05.000000000Z07:00"
@nathanielc feedback incorporated, PR rebased and squashed! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
Required for all non-trivial PRs
The PagerDuty API has stepped to v2 and it's a pretty serious refactor of the endpoint. While the v1 endpoint is still supported for some time, it's in deprecated mode and will ultimately be replaced soon(ish).
https://v2.developer.pagerduty.com/docs/events-api-v2
https://v2.developer.pagerduty.com/docs/getting-started